<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('title', 'params');	// which fields are stored in language variations
	
	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {

		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('meta', $_id_meta, $a, $lang['text']);


		$DATA['object']['kind'] = ($DATA['object']['tag'] & 0xff);
		$DATA['object']['required'] = $DATA['object']['tag'] >> 8;


		switch (action(array('editor_save'))) {
		
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
				$temp = array();
	
				foreach($DATA['langs'] as $lang) {
				
					foreach($_values as $name) {
					
						$t = postdata($name);
						$temp[] = array_merge($_record, array('id_parent' => $a, 'name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
				
					}
	
				}

				dataset('db_delete', tb('data'), "id_data=$_id_meta AND id_parent=$a");
				dataset('db_insert', tb('data'), $temp);

				$t = ($temp = trim($_POST['title'][LANG_DEF])) ? $temp : $DATA['object']['data'][LANG_DEF]['title'];

				dataset('db_update', tb('data'), array(
					'name' => $t, 
					'value' => trim(strip_tags(postdata('value'))), 
					'tag' => (int)postdata('kind') + ( postdata('required') ? (1 << 8) : 0)), 
				"$_crit AND id=$a");
				


				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		
		}
	
			
	}
	return false;
	
} else exit;

?>
